#ifndef BASE_H_
#define BASE_H_

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>

#include <sqlite3.h>

#include "basic_types.h"

#define DB_PATH	"case.db"
class DB
{
public:
	DB();
	~DB();
	
public:
	int32 Init();
	int32 Close();
	int32 Update(const char8 *pStr);
	int32 Query(const char8 *pStr, sqlite3_stmt **pStmt);
	
private:
	sqlite3 *m_pDB;
	
};

//member callback support
//the code below was given by Chris Becke from stackoverflow.com. thank you
//example
/* class B {
public:
  BaseCB* a;
  void invokecb(int n){
    (*a)(n);
  }
};

class C {
  B b;
public:
  C(){
    b.a = new CCallback<C>(this,&C::cb);
    b.invokecb(3);
  };
  void cb(int n)
  {
    cout << n;
  }
};

C c; */
class BaseCB
{
public:
	virtual void operator()(void *p) = 0;
};

template<class ClassT>
class CCallback 
	: public BaseCB
{
public:
	typedef void(ClassT::* FuncT)(void *);
	FuncT _fn;
	ClassT	*_c;
	CCallback(ClassT *c, FuncT fn):_fn(fn),_c(c){}
	
	void operator()(void *p)
	{
		return (_c->*_fn)(p);
	}
};

char *GetTimeStr(char *pStr);

char *GetShortTimeStr(char *pStr);

int GetDayofWeek();

enum
{
	SUN = 0,
	MON,
	TWE,
	WED,
	THU,
	FRI,
	SAT
};


#endif